﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading.Tasks;

namespace CloudReader.IO.Update
{
    public class VersionManager
    {
        BinaryFormatter bf;
        public VersionManager() => bf = new BinaryFormatter();
        public VersionTable Load(string version)
        {
            if (System.IO.File.Exists(version))
            {
                try
                {
                    return  (VersionTable)bf.Deserialize(System.IO.File.OpenRead(version));
                }
                catch
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
        public void Save(string saveFile, VersionTable vt)
        {
            var stream = System.IO.File.Create(saveFile);
            bf.Serialize(stream, vt);

        }
    }
}
